package com.lanf.lesson5_0.config;

import com.lanf.lesson5_0.web.interceptor.LogInterceptor;
import com.lanf.lesson5_0.web.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: lesson5_0
 * @description: 自定义WebMvcConfig类
 * @author: 蓝建平
 * @create: 2020-10-07 18:24
 **/
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/2login").setViewName("login");
        //相当于
      /*  @RequestMapping("/2login")
        public String toLogin()
        {
            return "login";
        }*/
    }

    @Autowired
    private LogInterceptor logInterceptor;
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/admin/login");
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login");
    }
}
